import { message } from 'antd';
import { request } from '@umijs/max';
import type { PageResult, Post } from '@/models/home';

/**
 * 获取首页文章列表参数类型
 */
export interface PostListParams {
  current?: number;
  pageSize?: number;
  title?: string;
  createBy?: number;
}

/**
 * 获取首页文章列表
 * @param params - 查询参数
 */
export const getPostList = async (params: PostListParams): Promise<PageResult<Post> | null> => {
  try {
    const response = await request('/post/page', {
      method: 'GET',
      params,
    });

    return response;
  } catch (error) {
    message.error('获取文章列表失败，请稍后重试');
    return null;
  }
};

